package com.fr.data.core.define;

import com.fr.base.StringUtils;
import com.fr.base.core.BaseCoreUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.data.core.DataXMLUtils;
import com.fr.data.impl.Connection;
import com.fr.data.impl.DirectoryConnection;
import com.fr.report.parameter.Parameter;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class FileDataSource
  implements DataSource
{
  private DirectoryConnection directoryConnection = null;
  private String filePath = null;

  public FileDataSource()
  {
  }

  public FileDataSource(DirectoryConnection paramDirectoryConnection, String paramString)
  {
    this.directoryConnection = paramDirectoryConnection;
    this.filePath = paramString;
  }

  public DirectoryConnection getDirectoryConnection()
  {
    return this.directoryConnection;
  }

  public void setDirectoryConnection(DirectoryConnection paramDirectoryConnection)
  {
    this.directoryConnection = paramDirectoryConnection;
  }

  public String getFilePath()
  {
    return this.filePath;
  }

  public void setFilePath(String paramString)
  {
    this.filePath = paramString;
  }

  public InputStream getSourceStream(Parameter[] paramArrayOfParameter)
    throws Exception
  {
    if ((this.directoryConnection == null) || (StringUtils.isBlank(this.filePath)))
      return null;
    File localFile = new File(this.directoryConnection.getLocation());
    if ((!(localFile.isDirectory())) || (this.filePath == null))
      return null;
    return new FileInputStream(BaseCoreUtils.pathJoin(new String[] { localFile.getAbsolutePath(), this.filePath }));
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str2 = paramXMLableReader.getTagName();
      if ("FilePath".equals(str2))
      {
        String str1;
        if ((str1 = paramXMLableReader.getElementValue()) != null)
          this.filePath = str1.trim();
      }
      else if ("Connection".equals(str2))
      {
        Connection localConnection = DataXMLUtils.readXMLConnection(paramXMLableReader);
        if (localConnection instanceof DirectoryConnection)
          this.directoryConnection = ((DirectoryConnection)localConnection);
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    if (this.filePath != null)
      paramXMLPrintWriter.startTAG("FilePath").textNode(getFilePath()).end();
    if (this.directoryConnection != null)
      DataXMLUtils.writeXMLConnection(paramXMLPrintWriter, this.directoryConnection);
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof FileDataSource) && (ComparatorUtils.equals(this.directoryConnection, ((FileDataSource)paramObject).directoryConnection)) && (ComparatorUtils.equals(this.filePath, ((FileDataSource)paramObject).filePath)));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    FileDataSource localFileDataSource = (FileDataSource)super.clone();
    if (this.directoryConnection != null)
      localFileDataSource.setDirectoryConnection((DirectoryConnection)this.directoryConnection.clone());
    return localFileDataSource;
  }
}